load("@rules_proto//proto:defs.bzl", "proto_library")
load("@build_stack_rules_proto//rules/cc:grpc_cc_library.bzl", "grpc_cc_library")
load("@build_stack_rules_proto//rules/cc:proto_cc_library.bzl", "proto_cc_library")
load("@build_stack_rules_proto//rules/closure:grpc_closure_js_library.bzl", "grpc_closure_js_library")
load("@build_stack_rules_proto//rules/closure:proto_closure_js_library.bzl", "proto_closure_js_library")
load("@build_stack_rules_proto//rules/go:proto_go_library.bzl", "proto_go_library")
load("@build_stack_rules_proto//rules/java:grpc_java_library.bzl", "grpc_java_library")
load("@build_stack_rules_proto//rules/java:proto_java_library.bzl", "proto_java_library")
load("@build_stack_rules_proto//rules/nodejs:grpc_nodejs_library.bzl", "grpc_nodejs_library")
load("@build_stack_rules_proto//rules/nodejs:grpc_web_js_library.bzl", "grpc_web_js_library")
load("@build_stack_rules_proto//rules/nodejs:proto_nodejs_library.bzl", "proto_nodejs_library")
load("@build_stack_rules_proto//rules/py:grpc_py_library.bzl", "grpc_py_library")
load("@build_stack_rules_proto//rules/py:proto_py_library.bzl", "proto_py_library")
load("@build_stack_rules_proto//rules/scala:grpc_scala_library.bzl", "grpc_scala_library")
load("@build_stack_rules_proto//rules/ts:proto_ts_library.bzl", "proto_ts_library")
load("@build_stack_rules_proto//rules:proto_compile.bzl", "proto_compile")
load("@aspect_rules_js//js:defs.bzl", "js_library")

# gazelle:proto_plugin ts_proto option nestJs=true

filegroup(
    name = "features",
    srcs = ["features.json"],
    visibility = ["//visibility:public"],
)

js_library(
    name = "features_json",
    srcs = ["features.json"],
    visibility = ["//example/routeguide/nodejs:__pkg__"],
)

genrule(
    name = "feature_db_json",
    srcs = ["features.json"],
    outs = ["feature_db.json"],
    cmd = """
    echo -n '{ "feature": ' > $@
    cat $< >> $@
    echo '}' >> $@
    """,
)

filegroup(
    name = "feature_db",
    srcs = ["feature_db.json"],
    visibility = ["//visibility:public"],
)

# --- generated rules below here ---

proto_library(
    name = "routeguide_proto",
    srcs = ["routeguide.proto"],
    visibility = ["//visibility:public"],
)

grpc_closure_js_library(
    name = "routeguide_grpc_closure_js_library",
    srcs = ["routeguide.grpc.js"],
    suppress = [
        "JSC_IMPLICITLY_NONNULL_JSDOC",
        "JSC_UNUSED_LOCAL_ASSIGNMENT",
    ],
    visibility = ["//visibility:public"],
    exports = [":routeguide_closure_js_library"],
    deps = [":routeguide_closure_js_library"],
)

proto_closure_js_library(
    name = "routeguide_closure_js_library",
    srcs = ["routeguide_closure.js"],
    internal_descriptors = ["//example/routeguide:routeguide_proto"],
    suppress = [
        "JSC_IMPLICITLY_NONNULL_JSDOC",
        "JSC_UNUSED_LOCAL_ASSIGNMENT",
    ],
    visibility = ["//visibility:public"],
    exports = [],
)

proto_compile(
    name = "routeguide_closure_js_compile",
    options = {
        "@build_stack_rules_proto//plugin/builtin:closurejs": [
            "import_style=closure",
            "library=example/routeguide/routeguide_closure",
        ],
        "@build_stack_rules_proto//plugin/stackb/grpc_js:protoc-gen-grpc-js": ["out=example/routeguide/routeguide.grpc.js"],
    },
    outputs = [
        "routeguide.grpc.js",
        "routeguide_closure.js",
    ],
    plugins = [
        "@build_stack_rules_proto//plugin/builtin:closurejs",
        "@build_stack_rules_proto//plugin/stackb/grpc_js:protoc-gen-grpc-js",
    ],
    proto = "routeguide_proto",
    visibility = ["//visibility:public"],
)

grpc_cc_library(
    name = "routeguide_grpc_cc_library",
    srcs = ["routeguide.grpc.pb.cc"],
    hdrs = ["routeguide.grpc.pb.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":routeguide_cc_library",
        "@com_github_grpc_grpc//:grpc++",
        "@com_github_grpc_grpc//:grpc++_reflection",
    ],
)

proto_cc_library(
    name = "routeguide_cc_library",
    srcs = ["routeguide.pb.cc"],
    hdrs = ["routeguide.pb.h"],
    visibility = ["//visibility:public"],
    deps = ["@com_google_protobuf//:protobuf"],
)

proto_compile(
    name = "routeguide_cpp_compile",
    outputs = [
        "routeguide.grpc.pb.cc",
        "routeguide.grpc.pb.h",
        "routeguide.pb.cc",
        "routeguide.pb.h",
    ],
    plugins = [
        "@build_stack_rules_proto//plugin/builtin:cpp",
        "@build_stack_rules_proto//plugin/grpc/grpc:protoc-gen-grpc-cpp",
    ],
    proto = "routeguide_proto",
    visibility = ["//visibility:public"],
)

proto_compile(
    name = "routeguide_go_compile",
    output_mappings = [
        "routeguide.pb.go=github.com/stackb/rules_proto/example/routeguide/routeguide.pb.go",
        "routeguide_grpc.pb.go=github.com/stackb/rules_proto/example/routeguide/routeguide_grpc.pb.go",
    ],
    outputs = [
        "routeguide.pb.go",
        "routeguide_grpc.pb.go",
    ],
    plugins = [
        "@build_stack_rules_proto//plugin/golang/protobuf:protoc-gen-go",
        "@build_stack_rules_proto//plugin/grpc/grpc-go:protoc-gen-go-grpc",
    ],
    proto = "routeguide_proto",
    visibility = ["//visibility:public"],
)

proto_go_library(
    name = "routeguide_go_proto",
    srcs = [
        "routeguide.pb.go",
        "routeguide_grpc.pb.go",
    ],
    importpath = "github.com/stackb/rules_proto/example/routeguide",
    visibility = ["//visibility:public"],
    deps = [
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_google_grpc//codes",
        "@org_golang_google_grpc//status",
        "@org_golang_google_protobuf//reflect/protoreflect",
        "@org_golang_google_protobuf//runtime/protoimpl",
    ],
)

grpc_java_library(
    name = "routeguide_grpc_java_library",
    srcs = ["routeguide_grpc.srcjar"],
    visibility = ["//visibility:public"],
    exports = [
        ":routeguide_java_library",
        "@com_google_guava_guava//jar",
        "@io_grpc_grpc_java//context",
        "@io_grpc_grpc_java//protobuf",
        "@io_grpc_grpc_java//stub",
        "@io_grpc_grpc_java//stub:javax_annotation",
    ],
    deps = [
        ":routeguide_java_library",
        "@com_google_guava_guava//jar",
        "@io_grpc_grpc_java//context",
        "@io_grpc_grpc_java//protobuf",
        "@io_grpc_grpc_java//stub",
        "@io_grpc_grpc_java//stub:javax_annotation",
    ],
)

proto_compile(
    name = "routeguide_java_compile",
    outs = {
        "@build_stack_rules_proto//plugin/builtin:java": "example/routeguide/routeguide.srcjar",
        "@build_stack_rules_proto//plugin/grpc/grpc-java:protoc-gen-grpc-java": "example/routeguide/routeguide_grpc.srcjar",
    },
    outputs = [
        "routeguide.srcjar",
        "routeguide_grpc.srcjar",
    ],
    plugins = [
        "@build_stack_rules_proto//plugin/builtin:java",
        "@build_stack_rules_proto//plugin/grpc/grpc-java:protoc-gen-grpc-java",
    ],
    proto = "routeguide_proto",
    visibility = ["//visibility:public"],
)

proto_java_library(
    name = "routeguide_java_library",
    srcs = ["routeguide.srcjar"],
    visibility = ["//visibility:public"],
    exports = ["@com_google_protobuf//:protobuf_java"],
    deps = ["@com_google_protobuf//:protobuf_java"],
)

grpc_nodejs_library(
    name = "routeguide_grpc_nodejs_library",
    srcs = ["routeguide_grpc_pb.js"],
    visibility = ["//visibility:public"],
    deps = [":routeguide_nodejs_library"],
)

grpc_web_js_library(
    name = "routeguide_grpc_web_js_library",
    srcs = ["routeguide_grpc_web_pb.js"],
    visibility = ["//visibility:public"],
    deps = [
        ":routeguide_nodejs_library",
        "@org_golang_google_protobuf//reflect/protoreflect",
        "@org_golang_google_protobuf//runtime/protoimpl",
    ],
)

proto_compile(
    name = "routeguide_node_js_compile",
    options = {
        "@build_stack_rules_proto//plugin/builtin:commonjs": ["import_style=commonjs"],
        "@build_stack_rules_proto//plugin/grpc/grpc-node:protoc-gen-grpc-node": ["grpc_js"],
        "@build_stack_rules_proto//plugin/grpc/grpc-web:protoc-gen-grpc-web": [
            "import_style=commonjs+dts",
            "mode=grpcwebtext",
        ],
    },
    outputs = [
        "routeguide_grpc_pb.js",
        "routeguide_grpc_web_pb.js",
        "routeguide_pb.js",
    ],
    plugins = [
        "@build_stack_rules_proto//plugin/builtin:commonjs",
        "@build_stack_rules_proto//plugin/grpc/grpc-node:protoc-gen-grpc-node",
        "@build_stack_rules_proto//plugin/grpc/grpc-web:protoc-gen-grpc-web",
    ],
    proto = "routeguide_proto",
    visibility = ["//visibility:public"],
)

proto_nodejs_library(
    name = "routeguide_nodejs_library",
    srcs = ["routeguide_pb.js"],
    visibility = ["//visibility:public"],
)

grpc_py_library(
    name = "routeguide_grpc_py_library",
    srcs = ["routeguide_pb2_grpc.py"],
    visibility = ["//visibility:public"],
    deps = [":routeguide_py_library"],
)

proto_compile(
    name = "routeguide_python_compile",
    outputs = [
        "routeguide_pb2.py",
        "routeguide_pb2.pyi",
        "routeguide_pb2_grpc.py",
    ],
    plugins = [
        "@build_stack_rules_proto//plugin/builtin:pyi",
        "@build_stack_rules_proto//plugin/builtin:python",
        "@build_stack_rules_proto//plugin/grpc/grpc:protoc-gen-grpc-python",
    ],
    proto = "routeguide_proto",
    visibility = ["//visibility:public"],
)

proto_py_library(
    name = "routeguide_py_library",
    srcs = ["routeguide_pb2.py"],
    visibility = ["//visibility:public"],
    deps = ["@com_google_protobuf//:protobuf_python"],
)

grpc_scala_library(
    name = "routeguide_grpc_scala_library",
    srcs = [
        "routeguide_akka_grpc.srcjar",
        "routeguide_scala_grpc.srcjar",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "@maven_akka//:com_lightbend_akka_grpc_akka_grpc_runtime_2_12_2_1_3",
        "@maven_akka//:com_typesafe_akka_akka_actor_2_12",
        "@maven_akka//:com_typesafe_akka_akka_http_core_2_12",
        "@maven_akka//:com_typesafe_akka_akka_stream_2_12",
        "@maven_scala//:com_google_protobuf_protobuf_java",
        "@maven_scala//:com_thesamet_scalapb_lenses_2_12",
        "@maven_scala//:com_thesamet_scalapb_scalapb_runtime_2_12",
        "@maven_scala//:com_thesamet_scalapb_scalapb_runtime_grpc_2_12",
        "@maven_scala//:io_grpc_grpc_api",
        "@maven_scala//:io_grpc_grpc_protobuf",
        "@maven_scala//:io_grpc_grpc_stub",
    ],
)

proto_compile(
    name = "routeguide_scala_compile",
    options = {"@build_stack_rules_proto//plugin/scalapb/scalapb:protoc-gen-scala-grpc": ["grpc"]},
    outputs = [
        "routeguide_akka_grpc.srcjar",
        "routeguide_scala.srcjar",
        "routeguide_scala_grpc.srcjar",
    ],
    plugins = [
        "@build_stack_rules_proto//plugin/akka/akka-grpc:protoc-gen-akka-grpc",
        "@build_stack_rules_proto//plugin/scalapb/scalapb:protoc-gen-scala",
        "@build_stack_rules_proto//plugin/scalapb/scalapb:protoc-gen-scala-grpc",
    ],
    proto = "routeguide_proto",
    visibility = ["//visibility:public"],
)

proto_compile(
    name = "routeguide_ts_proto_compile",
    options = {"@build_stack_rules_proto//plugin/stephenh/ts-proto:protoc-gen-ts-proto": [
        "emitImportedFiles=false",
        "esModuleInterop=true",
        "nestJs=true",
    ]},
    outputs = ["routeguide.ts"],
    plugins = ["@build_stack_rules_proto//plugin/stephenh/ts-proto:protoc-gen-ts-proto"],
    proto = "routeguide_proto",
    visibility = ["//visibility:public"],
)

proto_ts_library(
    name = "routeguide_ts_proto",
    srcs = ["routeguide.ts"],
    visibility = ["//visibility:public"],
    deps = [
        "@//:node_modules/@nestjs/microservices",
        "@//:node_modules/@types/node",
        "@//:node_modules/long",
        "@//:node_modules/protobufjs",
        "@//:node_modules/rxjs",
    ],
)
